#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600

#include <Windows.h>
#include <ctime>
#include "DirectXInterface.h"
#include "graphics.h"
#include "Game.h"

DirectXInterface *dxInterface;
Graphics2D* graphics;

LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam )
{
	PAINTSTRUCT paintStruct;
	HDC hDC;
	switch( message )
	{
	case WM_PAINT:
		hDC = BeginPaint( hwnd, &paintStruct );
		EndPaint( hwnd, &paintStruct );
		break;
	case WM_DESTROY:
		PostQuitMessage( 0 );
		break;

	default:
		return DefWindowProc( hwnd, message, wParam, lParam );
	}
	return 0;
}

int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE prevInstance,
		LPWSTR cmdLine, int cmdShow )
{
	clock_t startTime = clock();
	double currentTime = 0;

	dxInterface = new DirectXInterface();
	dxInterface->Initialize(hInstance, prevInstance, cmdLine, cmdShow, WndProc, WINDOW_WIDTH, WINDOW_HEIGHT);
	graphics = new Graphics2D();
	graphics->Initialize(dxInterface);
	float clearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
	graphics->setClearColor(clearColor);

	Game* game = new Game();
	game->Load();

	// Demo Initialize
	MSG msg = { 0 };
	while( msg.message != WM_QUIT )
	{
		if( PeekMessage( &msg, 0, 0, 0, PM_REMOVE ) )
		{
			TranslateMessage( &msg );
			DispatchMessage( &msg );
		}

		game->Update(currentTime);
		game->Draw(graphics);
		
		currentTime = (double)(clock() - startTime) / CLOCKS_PER_SEC;
	}

	// Demo Shutdown
	return static_cast<int>( msg.wParam );
}